package main.test.SparkAPI.Baics.classApi

import javax.ws.rs.BeanParam

object SingletionObj {
  /**
   * Implement a singletion obj
   * Use obj as executable prog
   * define staic func in a companion obj
   * create factory method using apply func
   * the essence of oop is repre elements of real world using
   * clases that desc their behavior throuhg methods. In specifi senarios
   * such as configuration and mian entry point , need to instantiate a coding
   * element at most once; using called it singleton,In scala
   * create singleton using obj . encourage to disdinguish between static
   * and non static methods ;
   * non-static ones act on a specific instance of a class
   * while the staic ones belong to its general definiton.
   *
   * /////////////////////////////////////////////////////
   * impl non-static methods in class and static in obj
   * ///////////////////////////////////
   * In capstone, use an obj to define main entry point of your application
   *
   */

    def testVocabulary(): Unit ={
      /**
       * When using the object Vocabulary, you refer to it by name. Note that you do not use the
keyword new because you cannot request to instantiate an object explicitly.
       */
      println(
        Array(
          Vocabulary.sentenceA,
          Vocabulary.sentenceB,
          Vocabulary.sentenceC
        ).mkString("\n")
      )



    }

    def TestUdfRobot()={
      val tom = new RobotUDF("Tom") {
        override def welcome: String = Vocabulary.sentenceA
      }
      val alice = new RobotUDF("Alice"){
        override def welcome: String = Vocabulary.sentenceB
      }

      RobotUDF.mostTalktive(tom,alice)
    }
  def testApply() = {
    /**
     * In lesson7 , class have one construct
     * use it by new keyword.What if you want to use diff way of creating class
     * apply of a companion obj help it
     *

     */
    val tom = new PersonUDF("tom",22)
    val alice = new PersonUDF("alice",23)
    val f: PersonUDF = PersonUDF.apply(tom, alice)
    println(f.name)

  }





  def main(args: Array[String]): Unit = {
    testVocabulary()
    val tom = new RobotUDF("Tom") {
      override def welcome: String = Vocabulary.sentenceA
    }
    val alice = null
//    println(RobotUDF.mostTalktive(null,null).getName)
    println(tom.welcome)
    testApply()



  }

}
